package com.bkgy.modular.configureRules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.configureRules.dto.RigidSeedGrading1720Dto;
import com.bkgy.modular.configureRules.entity.RigidSeedGrading1720;
import com.bkgy.modular.configureRules.mapper.RigidSeedGrading1720Mapper;
import com.bkgy.modular.configureRules.service.RigidSeedGrading1720Service;
import com.bkgy.sys.common.entity.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @ClassName Grading1720ServiceImpl
 * @date 2023/4/19 10:15
 */
@Service
public class RigidSeedGrading1720ServiceImpl extends ServiceImpl<RigidSeedGrading1720Mapper, RigidSeedGrading1720> implements RigidSeedGrading1720Service {
    @Resource
    private RigidSeedGrading1720Mapper rigidSeedGrading1720Mapper;

    @Override
    public ResultData findRigidSeedConfiguration() {
        List<RigidSeedGrading1720> rigidSeedGrading1720List = rigidSeedGrading1720Mapper.selectList(null);
        return ResultData.ResultDataFaultSelf("操作成功",rigidSeedGrading1720List);
    }

    @Override
    public ResultData updateRigidSeedConfiguration1720(RigidSeedGrading1720Dto dto) {
        String inner_grade = dto.getInner_grade();
        if (StringUtils.isEmpty(inner_grade)) {
            return ResultData.ResultDataFaultSelf("参数有误,请检查参数",-1);
        }
        LambdaQueryWrapper<RigidSeedGrading1720> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RigidSeedGrading1720::getInner_grade,inner_grade);
        RigidSeedGrading1720 rigidSeedGrading1720 = rigidSeedGrading1720Mapper.selectOne(queryWrapper);

        String remarks = dto.getRemarks();
        Double group_id = dto.getGroup_id();
        Double yield = dto.getYield();
        rigidSeedGrading1720.setRemarks(remarks);
        rigidSeedGrading1720.setGroup_id(group_id);
        rigidSeedGrading1720.setYield(yield);
        int flag = rigidSeedGrading1720Mapper.update(rigidSeedGrading1720,queryWrapper);
        return ResultData.ResultDataFaultSelf("修改状态",flag);
    }
}
